const mongoose = require("mongoose");
const dayjs = require("dayjs");

const Schema = new mongoose.Schema({
    name: { type: String, required: true, unique: true },
    thumbnail: { type: String, required: true },
    createdAt: { type: String, select: false },
    isActive: { type: Boolean, default: true, select: false }
});

Schema.pre("save", function (next) {
    if (this.isNew) {
        this.createdAt = dayjs().format("YYYY/MM/DD HH:mm:ss");
    }
    next();
});

module.exports = mongoose.model("Category", Schema);
